//
//  GHMainViewController.swift
//  光辉微博
//
//  Created by guanghui  shi on 2017/1/8.
//  Copyright © 2017年 guanghui  shi. All rights reserved.
//

import UIKit

class GHMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        setUpChildVc()
    
    }

    
}
//extension 类似于OC的分类，在swift中可以切分代码块
//可以把相近功能的函数，放在extension中
//便于代码维护
//注意：和oc中一样，不能定义属性
extension GHMainViewController{

    ///设置所有子控制器
     func setUpChildVc(){
    
        let array = [["clsName":"GHHomeViewController","title":"首页","imageName":""],]
        var arrayM = [UIViewController]()
        for dict in array {
            
            arrayM.append(controllsr(dict: dict))
        }
        
        
        
    
    }
    
    private func controllsr(dict:[String :String])->UIViewController{
    
        //1.取得字典内容
        guard let clsName = dict["clsName"],
                  let title = dict["title"],
                  let imageName = dict["imageName"],
                  let cls = NSClassFromString(Bundle.main.namespace + "." + clsName) as? GHBaseViewController.Type
        else {
            return UIViewController()
        }
    
    
        //2.创建视图控制器
        let vc = cls.init()
        vc.title = title;
        let nav = GHNavViewController(rootViewController: vc)
        return nav
        
    }
    
}



















